<?php
/**
 * Controller Hook
 * @author: NguyenNB
 */
class Controller_Hook {

    /**
     * Hold controller instance
     * @var type 
     */
    private $core;

    /**
     * Constructor
     */
    public function __construct()
    {
        //Get controller instance
        $this->core = & MY_Controller::get_instance();
    }

    /**
     * Use to parse view automatically
     */
    public function parse_view()
    {
        if ($this->core->disable_view)
        {
            return true;
        }

        //Set view path
        $view_path = $this->core->router->fetch_module() . '/' .
                $this->core->router->fetch_class() . '/' .
                $this->core->router->fetch_method();

        //If layout is not disabled, load layout with $content
        if (!$this->core->disable_layout)
        {
            $this->core->load->layout($this->core->layout_name, array(
                'content' => $this->core->load->view(
                    $view_path, $this->core->view_vars, true
                )
            ));
        } 
        else
        {
            $this->core->load->view(
                $view_path, $this->core->view_vars
            );
        }
    }

}
